<?php 
if (! defined('BASEPATH')) {
	exit('Access Denied');
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>模块树类别管理</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/static/css/admin/base.css">
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/static/css/admin/page.css">
<link rel="stylesheet" href="<?php echo base_url();?>/static/js/editor/themes/default/default.css" />

<script src="<?php echo base_url();?>/static/js/jquery.js" language="javascript"></script>

<script src="<?php echo base_url();?>/static/js/validate/validator.js" language="javascript"></script>
<script type="text/javascript">
$(document).ready(function() {

	$("#btnSave").click(function(){
		if($("#newform").Valid() == false || !$("#newform").Valid()) return false;
		var typename = $("#typename").val();
		var url="<?php echo site_url("admin/admin_tree/tree_type/tree_type_add");?>";
	
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "typename="+typename,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			if(code >0){
				common_request(1);
			}
		   },
		   beforeSend:function(){
			  
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});
	});
	common_request(1);
});

function common_request(page){
		var url = "<?php echo site_url("admin/admin_tree/tree_type/typelist");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=ajax_data&page="+page,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			
			filldata(msg.resultinfo.list.result,msg.resultinfo.list.page_string);
		   },
		   beforeSend:function(){
			   $("#result_p").html("<tr bgcolor=\"#FFFFFF\" align='center' height='50'><td colspan='9'><img src='http://localhost/ci//static/image/admin/loadding.gif'></td></tr>"); 
			   $("#mynew_page").html(''); 
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});
		
}

function filldata(data,page_string){
	var shtml = '' ;
	if(data){
		for(var j in data){
			shtml+='<tr bgcolor="#FFFFFF" onmousemove="javascript:this.bgColor=\'#FCFDEE\';" onmouseout="javascript:this.bgColor=\'#FFFFFF\'" id="list_tr_'+data[j]['id']+'">';
			shtml+='<td align="center">'+data[j]['id']+'</td>';
			shtml+='<td><input id="id" class="np" type="checkbox" value="'+data[j].id+'" name="id"></td>';
			shtml+='<td align="center"  id="tr_td_'+data[j]['id']+'">'+data[j]['typename']+'</td>';
			shtml+='<td align="center">'+data[j]['addtime']+'</td>';
			shtml+='<td align="center">'+data[j]['addperson']+'</td>';
			shtml+='<td align="center">'+data[j]['status']+'</td>';
			shtml+='<td align="center">'+data[j]['ismake']+'</td>';
			shtml+='<td align="center">'+data[j]['filepath']+'</td>';
			shtml+='<td align="center">'+data[j]['filetime']+'</td>';
			shtml+='<td align="center"><a href="<?php echo site_url("admin/admin_tree/tree_type/update_type_name");?>?id='+data[j].id+'"><img src="<?php echo base_url();?>/static/image/admin/edit.png"></td>';
			shtml+='</tr>';
		}
	}
	
	$("#result_p").html(shtml);
	$("#mynew_page").html(page_string);
}

function ajax_data(page){
	common_request(page);
}


//编辑 类别名称
function edit(id,o){
if($("#text_"+id).length<=0){
	var v  = o.innerHTML ;
	o.innerHTML = '' ;
	
	$("#tr_td_"+id).append("<input type='text' id='text_"+id+"' value="+v+" onblur=\"do_edit("+id+",\'"+v+"\')\">");
	$("#text_"+id).focus();
}

}
//处理编辑
function do_edit(id,oldtagname){
		var tagname = $("#text_"+id).val();
		if(oldtagname == tagname){
			$("#tr_td_"+id).html(oldtagname);
			return  ;
		}
		if(tagname == ''){
			return ;
		}
		var url = "<?php echo site_url("admin/admin_tree/tree_type/update_type_name");?>";
		$.ajax({
		   type: "POST",
		   url: url ,
		   data: "action=edit_type&id="+id+"&typename="+tagname,
		   cache:false,
		   dataType:"json",
		   async:true,
		   success: function(msg){
			
			var code = msg.resultcode ;
			if(code <0){//无权限
				window.location.href="<?php echo site_url('admin/login/jump_permition_html');?>" ;
				return false ;
			}  
			
			$("#tr_td_"+id).html($("#text_"+id).val());
		   },
		   beforeSend:function(){
			
		   },
		   error:function(){
			   alert('服务器繁忙,请稍候....');
		   }
		  
		});		
	
	
}
function selAll()
{
	for(i=0;i<document.form2.id.length;i++)
	{
		if(!document.form2.id[i].checked)
		{
			document.form2.id[i].checked=true;
		}
	}
}
function noSelAll()
{
	for(i=0;i<document.form2.id.length;i++)
	{
		if(document.form2.id[i].checked)
		{
			document.form2.id[i].checked=false;
		}
	}
}
function make_(){
	var num = 0 ;
	var str = '' ;
	var ids = document.getElementsByName("id") ;
	for(var k = 0 ; k<ids.length ;k++){
		if(ids[k].checked){
			num++ ;
			str+=ids[k].value+"," ;
		}
	}
	if(num <= 0 ){
		alert('请选择生成');
		return false ;
	}
	str = str.substring(0,str.length-1);
	$("#make_id").val(str);
	
}
</script>
</head>
<body leftmargin="8" topmargin="8">
<div class="nav_des">
<span class="des">模块树>></span>
	<a href="<?php echo site_url("admin/admin_tree/tree/tree_list");?>">模块树</a>

	<a href="javascript:void(0)" class="nav_des_hover">模块树类别</a>
</div>

<!--  内容列表   -->
<form id="newform">
<input type="hidden" value="tagsadd" name="action">

<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">

<tr align="" bgcolor="#FAFAF1" height="22">
	<td >类别名称：<input type="text" name="typename" class="form_input"  required="true" errmsg="请输入60个字符之内" tip="请输入60个字符之内" style="width:300px" id="typename"> </td>
</tr>
<tr bgcolor="#FAFAF1">
<td height="28" colspan="">
	&nbsp;

	<input type="button" value="提&nbsp;&nbsp;交" class="coolbg" id='btnSave'>
</td>
</tr>

</table>

</form>

<form name="form2" id="" name="" action="<?php echo site_url("admin/admin_tree/tree/make_xml");?>" target="make_iframe" onsubmit="return make_()">
<input type="hidden" value="tree_type_make" name="action">
<input type="hidden" value="" name="make_id" id="make_id">
<table width="98%" border="0" cellpadding="2" cellspacing="1" bgcolor="#D1DDAA" align="center" style="margin-top:8px">

<tr align="center" bgcolor="#FAFAF1" height="22">
	<td width="6%">ID</td>
	<td width="2%">选择</td>
	<td width="20%">类别名称</td>
	<td width="10%">添加时间</td>
	<td width="7%">添加人</td>
	<td width="5%">状态</td>
	<td width="6%">缓存是否生成</td>
	<td width="10%">文件路径</td>
	<td width="10%">生成时间</td>
	<td width="4%">操作</td> 
	
</tr>
<tbody id="result_p">

</tbody>
<tr bgcolor="#FAFAF1">
<td height="28" colspan="13">
	&nbsp;
	<a href="javascript:selAll()" class="coolbg">全选</a>
	<a href="javascript:noSelAll()" class="coolbg">取消</a>&nbsp;
	<input type="submit" name="" value="生成数据缓存"  style="cursor:pointer">
</td>
</tr>
<tr align="right" bgcolor="#EEF4EA">

	<td height="36" colspan="13" align="right" id="mynew_page">
	
	<!--翻页代码 -->
	</td>
</tr>

<tr align="right" bgcolor="#EEF4EA">

	<td colspan="13" >
	
	<iframe style="border:none;width:100%" name="make_iframe"></iframe>
	</td>
</tr>

</table>
</form>
</body>
</html>